package com.example.easypoi.demo2.controller;

import com.example.easypoi.demo2.entity.CourseExportVO;
import com.example.easypoi.demo2.entity.StudentExportVO;
import com.example.easypoi.demo2.entity.TeacherExportVO;
import com.example.easypoi.demo2.util.ExcelUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class CourseController {
    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response) throws IOException {
        //1. 学生数据
        List<StudentExportVO> students1 = new ArrayList<>();
        students1.add(new StudentExportVO("001", "悟纤", 1, new Date()));
        students1.add(new StudentExportVO("002", "刘亦菲", 0, new Date()));
        students1.add(new StudentExportVO("003", "赵丽颖", 0, new Date()));
        List<StudentExportVO> students2 = new ArrayList<>();
        students2.add(new StudentExportVO("001", "刘诗诗", 1, new Date()));
        students2.add(new StudentExportVO("002", "迪丽热巴", 0, new Date()));
        students2.add(new StudentExportVO("003", "杨幂", 0, new Date()));
        //2.老师数据.
        TeacherExportVO teacher1 = new TeacherExportVO("林老师");
        TeacherExportVO teacher2 = new TeacherExportVO("王老师");
        //3.课程数据以及关联数据.
        List<CourseExportVO> courseList = new ArrayList<>();
        courseList.add(new CourseExportVO("数学", teacher1, students1));
        courseList.add(new CourseExportVO("语文", teacher2, students2));

        ExcelUtil.exportExcel(courseList, "学生数据表", CourseExportVO.class, "测试导出表.xlsx", response);
    }
}
